package cn.graydove.bot.mirai

import cn.graydove.bot.support.BotProperties
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.Member
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.message.sendImage
import java.io.File
import java.io.InputStream

class Client(
    val bot: Bot,
    val sender: Member,
    val message: MessageChain,
    val subject: Group,
    val properties: BotProperties
) {


    private val matchNumber = Regex("[0-9]+")

    fun sendImage(file:File) {
        runBlocking {
            launch {
                subject.sendImage(file)
            }
        }
    }
    fun sendImage(inputStream: InputStream) {
        runBlocking {
            launch {
                subject.sendImage(inputStream)
            }
        }
    }
    fun sendMessage(message: String) {
        runBlocking {
            launch {
                subject.sendMessage(message)
            }
        }
    }
    fun sendMessage(message: Message) {
        runBlocking {
            launch {
                subject.sendMessage(message)
            }
        }
    }
    fun sendMessage(message: MessageChainBuilder) {
        runBlocking {
            launch {
                subject.sendMessage(message.build())
            }
        }
    }

    fun findNumber(text: String):String? {
        return matchNumber.find(text)?.value
    }

    fun find(regex: String, text: String):String? {
        return Regex(regex).find(text)?.value
    }
}